<?php

namespace App\Models\Factory;

use App\Models\AbsModelFactory;
use App\Models\Orm\Occupation;


/**
 * 职业工厂
 * Class SmsFactory
 * @package App\Models\Factory
 */
class OccupationFactory extends AbsModelFactory
{

    //添加修改职业信息
    public static function addOccupation($userId,$data)
    {
        $occupationObj = Occupation::where('uid', $userId)->first();
        if (empty($occupationObj)) {
            $occupationObj = new Occupation();
            $occupationObj  -> uid = $userId;
        }

        $occupationObj  -> school  = $data['occupation']['student']['school'];

        $occupationObj  ->address    = $data['occupation']['student']['address'];

        if( isset($data['occupation']['student']['preTeacherphone'])){
        $occupationObj  -> teacherphone = $data['occupation']['student']['preTeacherphone'].'-'.$data['occupation']['student']['teacherphone'] ;
        }else{
            $occupationObj  -> teacherphone = $data['occupation']['student']['teacherphone'];
        }

        $occupationObj  ->  company    = $data['occupation']['company']['company'];
        $occupationObj  -> location   = $data['occupation']['company']['location'];
        $occupationObj  -> years    = $data['occupation']['company']['years'];
        $occupationObj  -> cincome  = $data['occupation']['company']['cincome'];
        $occupationObj  -> email    = $data['occupation']['company']['email'];
        if( isset($data['occupation']['company']['preFixedline'])){
            $occupationObj  -> fixedline   = $data['occupation']['company']['preFixedline'].'-'.$data['occupation']['company']['fixedline'];
        }else{
            $occupationObj  -> fixedline   = $data['occupation']['company']['fixedline'];
        }






        $occupationObj  ->  bcompany    = $data['occupation']['business']['bcompany'];
        $occupationObj  -> blocation   = $data['occupation']['business']['blocation'];
        $occupationObj  -> byears    = $data['occupation']['business']['byears'];
        $occupationObj  -> bcincome  = $data['occupation']['business']['bcincome'];
        $occupationObj  -> bemail    = $data['occupation']['business']['bemail'];
        if(isset($data['occupation']['business']['bpreFixedline'])){
            $occupationObj  -> bfixedline   = $data['occupation']['business']['bpreFixedline'].'-'.$data['occupation']['business']['bfixedline'];
        }else{
            $occupationObj  -> bfixedline = $data['occupation']['business']['bfixedline'];
        }

        $occupationObj  -> operations = $data['occupation']['business']['operations'];
        $occupationObj  -> license    = $data['occupation']['business']['license'];



        $occupationObj  -> source    = $data['occupation']['freelancer']['source'];
        $occupationObj  -> olass_time = date("Y-m-d h:i:s",time());
        $occupationObj  -> status    = $data['occupation']['status'];
        if ($occupationObj->save()) {
            return true;
        } else {

            return false;
        }
    }

    //查看职业信息
    public static function getOccupation($userId)
    {
        $occupation = Occupation::where('uid',$userId)->first();

        if($occupation)
        {
            $occupation = $occupation -> toArray();
            $data1['isSuccess'] = "1";

            $data1['occupation']['student']['school'] = $occupation['school'];
            $data1['occupation']['student']['address'] = $occupation['address'];

            //把固话切割开,分为两段
            $teacherphone = explode('-',$occupation['teacherphone']);



            if(count($teacherphone)>1){

                $data1['occupation']['student']['preTeacherphone'] = $teacherphone[0];
                $data1['occupation']['student']['teacherphone'] = $teacherphone[1];
            }else{
                $data1['occupation']['student']['preTeacherphone'] = '86';
                $data1['occupation']['student']['teacherphone'] = $teacherphone[0];

            }




            $data1['occupation']['company']['company'] = $occupation['company'];
            $data1['occupation']['company']['location'] = $occupation['location'];
            $data1['occupation']['company']['years'] = $occupation['years'];
            $data1['occupation']['company']['email'] = $occupation['email'];
            $data1['occupation']['company']['cincome'] = $occupation['cincome'];

            //把固话切割开,分为两段
            $fixedline = explode('-',$occupation['fixedline']);

            $bfixedline = explode('-',$occupation['bfixedline']);
            //判断一下是否有区号
                if(count($fixedline)>1) {
                    $data1['occupation']['company']['preFixedline'] =$fixedline[0];
                    $data1['occupation']['company']['fixedline'] =$fixedline[1];
                }else{
                    $data1['occupation']['company']['preFixedline'] ='86';
                    $data1['occupation']['company']['fixedline'] =$fixedline[0];
                }

            //判断一下是否有区号
            if(count($bfixedline)>1) {
                $data1['occupation']['business']['bpreFixedline'] =$bfixedline[0];
                $data1['occupation']['business']['bfixedline'] =$bfixedline[1];
            }else{
                $data1['occupation']['business']['bpreFixedline'] ='86';
                $data1['occupation']['business']['bfixedline'] =$bfixedline[0];
            }





            $data1['occupation']['business']['bcompany'] = $occupation['bcompany'];
            $data1['occupation']['business']['blocation'] = $occupation['blocation'];
            $data1['occupation']['business']['byears'] = $occupation['byears'];
            $data1['occupation']['business']['bemail'] = $occupation['bemail'];
            $data1['occupation']['business']['bcincome'] = $occupation['bcincome'];
            $data1['occupation']['business']['operations'] = $occupation['operations'];
            $data1['occupation']['business']['license'] = $occupation['license'];


            $data1['occupation']['freelancer']['source'] = $occupation['source'];
            $data1['occupation']['olass_time'] = $occupation['olass_time'];
            $data1['status']              = "1";

            return $data1;

        }else{
            $data2['isSuccess'] = "1";
            $data2['occupation']['student']['school'] = "";
            $data2['occupation']['student']['address'] = "";
            $data2['occupation']['student']['information'] = "";
            $data2['occupation']['student']['freelancer'] = "";
            $data2['occupation']['student']['teacherphone'] = "";
            $data2['occupation']['student']['preTeacherphone'] = "";


            $data2['occupation']['company']['company'] = "";
            $data2['occupation']['company']['location'] = "";
            $data2['occupation']['company']['years'] = "";
            $data2['occupation']['company']['email'] = "";
            $data2['occupation']['company']['cincome'] = "";
            $data2['occupation']['company']['fixedline'] = "";
            $data2['occupation']['company']['preFixedline'] = "";


            $data2['occupation']['business']['bcompany'] = "";
            $data2['occupation']['business']['blocation'] = "";
            $data2['occupation']['business']['byears'] = "";
            $data2['occupation']['business']['bemail'] = "";
            $data2['occupation']['business']['bcincome'] = "";
            $data2['occupation']['business']['bfixedline'] = "";
            $data2['occupation']['business']['bpreFixedline'] = "";
            $data2['occupation']['business']['operations'] = "";
            $data2['occupation']['business']['license'] = "";
            $data2['occupation']['business']['employment'] = "";
            $data2['occupation']['business']['nature'] = "";

            $data2['occupation']['freelancer']['source'] = "";
            $data2['occupation']['olass_time'] = "";
            $data2['status']              = "1";

            return $data2;

        }
    }
}